/****

    activequant - activestocks.eu

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

	
	contact  : contact@activestocks.eu
    homepage : http://www.activestocks.eu

****/
package org.activequant.core.domainmodel.account;


import static org.activequant.util.tools.IdentityUtils.equalsTo;
import static org.activequant.util.tools.IdentityUtils.safeCompare;
import static org.activequant.util.tools.IdentityUtils.safeHashCode;

import java.io.Serializable;

/**
 * brokeraccount holds all information for a specific broker or bank account. 
 * details on the documentation are available in the pdf/html documentation. 
 * Holds the following associated variables:
 * <ul>
 * <li>id(Long)</li>
 * <li>holder(String)</li>
 * <li>brokerName(String)</li>
 * <li>balanceBook(BalanceBook)</li>
 * <li>orderBook(OrderBook)</li>
 * <li>portfolio(Portfolio)</li>
 * <li>transactionBook(TransactionBook)</li>
 * </ul>
 * <br/>
 * <b>History:</b><br/>
 *  - [09.06.2007] Created (Ulrich Staudinger)<br>
 *  - [14.06.2007] added transaction book (Ulrich Staudinger)<br>
 *  - [14.07.2007] Added persistence (Erik Nijkamp)<br>
 *  - [29.09.2007] Removed annotations (Erik Nijkamp)<br>
 *  - [16.12.2007] Cleanup (Mike Kroutikov)<br>
 *
 *  @author Ulrich Staudinger
 */
public class BrokerAccount implements Comparable<BrokerAccount>, Serializable {
	
	private static final long serialVersionUID = 1646289536438187173L;
	/**
	 * private Long id;
	 */
	private Long id;
	/**
	 * private String holder;
	 */
	private String holder;
	/**
	 * private String brokerName;
	 */
	private String brokerName;
	/**
	 * private Portfolio portfolio = new Portfolio();
	 */
	private Portfolio portfolio = new Portfolio();
	/**
	 * private BalanceBook balanceBook = new BalanceBook();
	 */
	private BalanceBook balanceBook = new BalanceBook();
	/**
	 * private OrderBook orderBook = new OrderBook();
	 */
	private OrderBook orderBook = new OrderBook();
	/**
	 * private TransactionBook transactionBook = new TransactionBook();
	 */
	private TransactionBook transactionBook = new TransactionBook();
	/**
	 * an empty BrokerAccount constructor
	 */
	public BrokerAccount() {
	}
	/**
	 * constructs a BrokerAccount using the given brokerId(String) and holder(String) to set its associated brokerName(String) and holder(String)
	 * @param brokerId
	 * @param holder
	 */
	public BrokerAccount(String brokerId, String holder) {
		this.brokerName = brokerId;
		this.holder = holder; 
	}
	/**
	 * returns whether the associated id(Long) is not <code>null</code>
	 * @return
	 */
	public boolean hasId() {
		return id != null;
	}
	/**
	 * returns the associated id(Long)
	 * @return
	 */
	public Long getId() {
		return id;
	}
	/**
	 * sets the associated id(Long) with the given id(Long)
	 * @param id
	 */
	public void setId(Long id) {
		this.id = id;
	}
	/**
	 * returns the associated balanceBook(BalanceBook)
	 * @return
	 */
	public BalanceBook getBalanceBook() {
		return balanceBook;
	}
	/**
	 * sets the associated balanceBook(BalanceBook) with the given balanceBook(BalanceBook)
	 * @param balanceBook
	 */
	public void setBalanceBook(BalanceBook balanceBook) {
		this.balanceBook = balanceBook;
	}
	/**
	 * returns the associated orderBook(OrderBook)
	 * @return
	 */
	public OrderBook getOrderBook() {
		return orderBook;
	}
	/**
	 * sets the associated orderBook(OrderBook) with the given orderBook(OrderBook)
	 * @param orderBook
	 */
	public void setOrderBook(OrderBook orderBook) {
		this.orderBook = orderBook;
	}
	/**
	 * returns the associated transactionBook(TransactionBook)
	 * @return
	 */
	public TransactionBook getTransactionBook() {
		return transactionBook;
	}
	/**
	 * sets the associated transactionBook(TransactionBook) with the given transactionBook(TransactionBook)
	 * @param transactionBook
	 */
	public void setTransactionBook(TransactionBook transactionBook) {
		this.transactionBook = transactionBook;
	}
	/**
	 * returns the associated portfolio(Portfolio)
	 * @return
	 */
	public Portfolio getPortfolio() {
		return portfolio;
	}
	/**
	 * sets the associated portfolio(Portfolio) with the given portfolio(Portfolio)
	 * @param portfolio
	 */
	public void setPortfolio(Portfolio portfolio) {
		this.portfolio = portfolio;
	}
	/**
	 * returns the associated holder(String)
	 * @return
	 */
	public String getHolder() {
		return holder;
	}
	/**
	 * sets the associated holder(String) with the given holder(String)
	 * @param holder
	 */
	public void setHolder(String holder) {
		this.holder = holder;
	}
	
	public int compareTo(BrokerAccount other) {
		return safeCompare(holder, other.holder);
	}
	
	public int hashCode() {
		return safeHashCode(holder);
	}
	
	public boolean equals(Object o) {
		return equalsTo(this, o);
	}
	/**
	 * returns the associated brokerName(String)
	 * @return
	 */
	public String getBrokerName() {
		return brokerName;
	}
	/**
	 * sets the associated brokerName(String) with the given brokerId(String)
	 * @param brokerId
	 */
	public void setBrokerName(String brokerId) {
		this.brokerName = brokerId;
	}
}